<?php
class Administrador_controller
{
	function login()
	{
		$data['user'] = $_POST["user"];
		$data['pass'] = $_POST["pass"];
		
		if (!empty($data['user']) && !empty($data['pass']))
		{
			$administrador_model = new Administrador_Model();
			$usuario = $administrador_model -> get_usuario($data);
			
			if (!empty($usuario['rol']))
			{
				session_start();
		
				$_SESSION["admin_user"] = $usuario['id_usuario'];
			}
		
			
		}
		
		header("Location: index.php?action=Catalogo::get_libros&id=1");
		
	}
	
	function logon()
	{
		session_start();
		
		unset($_SESSION["admin_user"]);
		
		session_destroy();
	
		header("Location: index.php?action=Catalogo::get_libros&id=1");
	}

	function change_pass()
	{
		$tpl = new TemplatePower("templates/change_pass.html" );
		$tpl -> prepare();
		$tpl -> gotoBlock('_ROOT');
		
		return $tpl -> getOutputContent();
	}
	
	function update_pass()
	{
			session_start();
						
			$data['id_usuario'] = $_SESSION["admin_user"];
			
			if (!empty($data['id_usuario']))
			{
				$data['pass'] = $_POST["pass"];
				$data['repeatPass'] = $_POST["repeatPass"];
			
					if (!empty($data['pass']) && !empty($data['repeatPass']) && $data['pass'] == $data['repeatPass'])
					{
						$administrador_model = new Administrador_Model();
						$usuario = $administrador_model -> set_pass($data);
						
						
					}
			}
			
			header("Location: index.php?action=Catalogo::get_libros&id=1");
	}
	
}

?>